fid = fopen('DJIA_1928_2011.txt','rt');
nLines = 0;
while (fgets(fid) ~= -1),
  nLines = nLines+1;
end
fclose(fid);
[date, open, high, low,close ,volume,adjclose] = textread('DJIA_1928_2011.txt','%s %f %f %f %f %f %f', nLines);
date=date(length(date):-1:1);
open=open(length(date):-1:1);
close=close(length(date):-1:1);
high=high(length(date):-1:1);
low=low(length(date):-1:1);
volume=volume(length(date):-1:1);
adjclose=adjclose(length(date):-1:1);

y=(close(1:length(close)-1)<=open(2:length(close)));
diffval=(close(1:length(close)-1)~=open(2:length(close)))+(open(2:length(close))~=close(2:length(close)));
date=date(diffval>0);
open=open(diffval>0);
close=close(diffval>0);
high=high(diffval>0);
low=low(diffval>0);
y=y(diffval>0);
adjclose=adjclose(diffval>0);
str=[];
%fid = fopen('labeling.txt','w');
for i=1:length(open)
    str=[str, sprintf('%d %2f %2f %2f %2f %2f %2f %s\n',y(i),open(i),close(i),high(i),low(i),volume(i),adjclose(i),char(date(i)))];
end
fid = fopen('djlabeling.txt','w');
save('stocks.mat','y','date')
fprintf(fid,str);